package com.zhanghe.mall.service.impl;

import com.zhanghe.mall.pojo.AttributeProperty;
import com.zhanghe.mall.pojo.ClassificationAttribute;
import com.zhanghe.mall.pojo.repository.AttributePropertyRepository;
import com.zhanghe.mall.service.AttributePropertyService;
import com.zhanghe.mall.service.dto.AddAttributePropertyDTO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AttributePropertyServiceImpl implements AttributePropertyService {

  @Autowired
  private AttributePropertyRepository attributePropertyRepository;

  @Override
  public AttributeProperty insert(AddAttributePropertyDTO addAttributePropertyDTO) {
    AttributeProperty attributeProperty = new AttributeProperty();
    BeanUtils.copyProperties(addAttributePropertyDTO,addAttributePropertyDTO);
    ClassificationAttribute classificationAttribute = new ClassificationAttribute();
    classificationAttribute.setId(addAttributePropertyDTO.getClassificationAttributeId());
    attributeProperty.setClassificationAttribute(classificationAttribute);
    return attributePropertyRepository.save(attributeProperty);
  }
}
